﻿using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Collections;

namespace TripLOA.WebService.Wrappers
{
    /// <summary>
    /// A serializable rapresentation of the Groupware.Notification class
    /// </summary>
    [DataContract]
    public class Notification
    {
        #region Constructors

        /// <summary>
        /// Parameterless Constructor
        /// </summary>
        public Notification() { }

        /// <summary>
        /// Constructor. Set all fields to the values of the given Notification object
        /// </summary>
        /// <param name="not">A Groupware.Notification object</param>
        public Notification(Groupware.Notification not)
        {
            this.EventId = not.EventId;
            this.Fields = ToArray(not.Fields);
            this.SenderID = not.SenderID;
            this.TemplateType = not.TemplateType;
            this.TripId = not.TripId;
            this.UserId = not.UserId;
        }
        #endregion

        #region methods
        private object[][] ToArray(Hashtable ht)
        {
            object[][] obj = new object[ht.Count][];
            int i = 0;
            foreach (object key in ht.Keys)
            {
                obj[i] = new object[] { key, ht[key] };
                i++;
            }
            return obj;
        }
        public Hashtable ToHashtable(object[][] obj)
        {
            Hashtable ht = new Hashtable(obj.Length);
            foreach (object[] pair in obj)
            {
                object key = pair[0];
                object value = pair[1];
                ht[key] = value;
            }
            return ht;
        }
        #endregion

        #region Properties
        [DataMember]
        public int? EventId { get; set; }

        [DataMember]
        public object[][] Fields { get ; set ; }

        [DataMember]
        public int? SenderID { get; set; }

        [DataMember]
        public int TemplateType { get; set; }

        [DataMember]
        public int? TripId { get; set; }

        [DataMember]
        public int? UserId { get; set; }

        #endregion
    }
    }
